<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.edu.lingnan.pojo.Competition" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>比赛项目列表</title>
    <link rel="stylesheet" type="text/css" href="../css/Compete.css">
    <script type="text/javascript" src="../js/competition.js"></script>
</head>
<body>
<header>
    <h1>比赛项目列表</h1>
    <hr>
</header>
<br>
<div style="display: flex; align-items: center; margin-bottom: 20px;">
    <a href="/loginOut" class="link-style">注销</a>
    <a href="/main.jsp" class="link-style">返回管理员首页</a></div>

<div class="container">
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
        <a href="addCompetition.jsp" class="link-style">添加项目</a>
        <form action="/queryAllCompete" method="get" id="comForm">
            <input type="text" id="comName" name="comName" placeholder="请输入查询比赛名称">
            <input type="submit" value="查询">
        </form>
    </div>

    <table>
        <thead>
        <tr>
            <th><input type="checkbox" onclick="allcheck(this);"></th>
            <th>比赛编号</th>
            <th>比赛名称</th>
            <th>比赛描述</th>
            <th>开始时间</th>
            <th>结束时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            List<Competition> competitions =(List<Competition>) session.getAttribute("competitions");
            boolean flag = false;
            if(competitions!=null&&!competitions.isEmpty()){
                flag = true;
            for(Competition competition:competitions){
        %>
        <tr>
            <td><input type="checkbox" name="check" value=<%=competition.getId()%>></td>
            <td><%=competition.getId()%></td>
            <td><%=competition.getName()%></td>
            <td><%=competition.getDescription()%></td>
            <td><%=competition.getStart_time()%></td>
            <td><%=competition.getEnd_time()%></td>
            <td>
                <a href="updateCompete.jsp?cid=<%=competition.getId()%>" class="link-style">修改</a> |
                <a href="delCom?cid=<%=competition.getId()%>" class="link-style">删除</a>
            </td>
        </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
    <%
        if(!flag) { // 表格为空,flag=ture语没有被执行，则！flag成功执行，显示图片
    %>
    <img src="/images/entry2.png" alt="空空如也">
    <%
        }
    %>
    <div style="text-align: right; margin-top: 20px;">
        <input type="submit" value="批量删除" onclick="delCheck1()">
    </div>
</div>
</body>
</html>